#pragma once

#include "../../Common/Interfaces/IServiceLocator.h"
#include "../../Common/Interfaces/IUserInterface.h"
#include "../../Common/Interfaces/IPlugin.h"
#include <map>
#include <AntTweakBar.h>
#include <AtlBase.h>
#include <AtlConv.h>


struct r_PluginElement
{
	r_PluginElement(int ai_Id1, int ai_Id2, int ai_Id3, IParameter* ar_Parameter_)
		: mi_ControlId(ai_Id1)
		, mi_DisplayId(ai_Id2)
		, mi_NameId(ai_Id3)
		, mr_Parameter_(ar_Parameter_)
	{}

	r_PluginElement()
		: mi_ControlId(-1)
		, mi_DisplayId(-1)
		, mi_NameId(-1)
		, mr_Parameter_(NULL)
	{}

	int mi_ControlId;
	int mi_DisplayId;
	int mi_NameId;
	IParameter* mr_Parameter_;
};


class k_UiHandler
	: public IUiHandler
{
public:
	k_UiHandler(IServiceLocator& ar_SvLocator);

	~k_UiHandler();

	// IObject
	void* QueryInterface(const GUID& ar_InterfaceGuid);

	void Close();

	IServiceLocator& get_ServiceLocator();

protected:
	void InitializeMainDialog();
	void LoadApplicationSettings();

	void BuildPluginSpecificDialog(IDirect3D9BasePlugin* ar_Plugin_, TwBar* ar_Bar);

	static void TW_CALL TogglePluginCallback(void* clientData);
	static void TW_CALL ShowPluginCallback(void* clientData);
	static void TW_CALL HidePluginCallback(void* clientData);
	static void TW_CALL ResetPluginCallback(void* clientData);
	static void TW_CALL ClosePluginDialogCallback(void* clientData);
	static void TW_CALL SaveSettingsDialogCallback(void* clientData);

	static void TW_CALL SetSliderCallback(const void *value, void *clientData);
	static void TW_CALL GetSliderCallback(void *value, void *clientData);
	static void TW_CALL SetEditBoxCallback(const void *value, void *clientData);
	static void TW_CALL GetEditBoxCallback(void *value, void *clientData);
	static void TW_CALL SetCheckBoxCallback(void *clientData);

	static void k_UiHandler::UpdateCheckBoxText(void *clientData);
	static void k_UiHandler::UpdateActiveText(void *clientData);
private:
	IServiceLocator& mr_ServiceLocator;
	static IServiceLocator* ms_ServiceLocator;
	TwBar* mr_PluginsBar_;

	std::map<IDirect3D9BasePlugin*, TwBar*> mk_PluginDialogs;
};
